package com.zzyl.service.impl;


import com.zzyl.dto.FloorDto;
import com.zzyl.entity.Floor;
import com.zzyl.mapper.FloorMapper;
import com.zzyl.service.BedService;
import com.zzyl.service.FloorService;
import com.zzyl.service.RoomService;
import com.zzyl.vo.FloorVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;


@Service

public class FloorServiceImpl implements FloorService {


    @Autowired
    RoomService roomService;

    @Autowired
    BedService bedService;

    @Autowired
    private FloorMapper floorMapper;



    @Override
    public List<FloorVo> getAllWithRoomAndBed() {
        return floorMapper.selectAllRoomAndBed();
    }

    @Override
    public List<FloorVo> selectAllByNur() {
        return floorMapper.selectAllByNur();
    }

    @Override
    public void addFloor(FloorDto floorDto) {
        Floor floor = new Floor();
        BeanUtils.copyProperties(floorDto, floor);
        floor.setCreateBy(1L);
        floor.setUpdateBy(1L);
        floor.setCreateTime(LocalDateTime.now());
        floor.setUpdateTime(LocalDateTime.now());
        floorMapper.addFloor(floor);
    }

    @Override
    public List<FloorVo> selectAll() {
        List<FloorVo> floorVos = floorMapper.selectAll();
        return floorVos;

    }

    @Override
    public void delete(Long id) {
        floorMapper.delete(id);
    }

    @Override
    public FloorVo findFloorById(Long id) {

        FloorVo floorVo = floorMapper.findFloorById(id);
        return floorVo;
    }

    @Override
    public void update(FloorDto floorDto) {
        Floor floor = new Floor();
        BeanUtils.copyProperties(floorDto, floor);
        floor.setUpdateTime(LocalDateTime.now());
        floorMapper.update(floor);

    }


}

